package redis

import (
	"context"
	"encoding/json"
	"gin-gorm-oj/models"
)

func Set(key string, data interface{}) (err error) {
	dataJson, err := json.Marshal(data)
	if err == nil {
		models.RDb.Set(context.Background(), key, dataJson, 0)

	}
	return
}

func Get(key string, result interface{}) (err error) {
	data, err := models.RDb.Get(context.Background(), key).Result()
	if err != nil {
		return err
	}
	return json.Unmarshal([]byte(data), result)
}
